package org.gwtunclutter.client;

import com.google.gwt.user.client.ui.*;

/**
 * Date: Jul 24, 2007
 * Time: 8:17:11 PM
 *
 * @author Alex
 */
public class WidgetDecorator {

  /** Adds a style to the given widget and returns it */
  public static Widget styledWidget(Widget w, String styleName) {
    w.setStyleName(styleName);
    return w;
  }

  /** Adds styles to the given widget and returns it */
  public static Widget styledWidget(Widget w, String styleName1, String styleName2) {
    w.addStyleName(styleName1);
    w.addStyleName(styleName2);
    return w;
  }

  /** Adds a title (help text) to the given widget and returns it */
  public static Widget titledWidget(Widget w, String title) {
    w.setTitle(title);
    return w;
  }

  /**
   * Allows method chaining when adding widgets to a panel.
   * Adds given widget to the given panel.
   * @return The original panel
   */
  public static Panel addToPanel(Panel panel, Widget widget) {
    panel.add(widget);
    return panel;
  }

  /**
   * Allows method chaining when adding widgets to a panel.
   * Adds given widgets to the given panel.
   * @return The original panel
   */
  public static Panel addToPanel(Panel panel, Widget[] widgets) {
    for (int i = 0; i < widgets.length; i++) {
      panel.add(widgets[i]);
    }
    return panel;
  }
}
